public class BubbleSort {
    
    public static void bubblesort(int[] elem){

        for (int i = 0; i < elem.length; i++) {
            boolean flg = false;
            for (int j = 0; j < elem.length-1-i; j++) {
                if (elem[j] > elem[j+1]){
                    swap(elem,j,j+1);
                    flg = true;
                }
                }
            if (!flg){
                return;
            }
        }
    }
    public static void swap(int[] elem, int i, int j){
        int cur = elem[i];
        elem[i] = elem[j];
        elem[j] = cur;
    }
}
